package com.awphone.data;

import com.awphone.data.constant.CommentVotesConst;
import com.awphone.data.constant.EObjectType;

import javax.persistence.*;
import java.util.Date;

/**
 * @author a_polyakov
 * Date: 05.03.13
 * Time: 0:38
 * Голосование за комментарий
 */
@Entity
@Table(schema = CommentVotesConst.SCHEMA_NAME, name = CommentVotesConst.TABLE_NAME, uniqueConstraints = @UniqueConstraint(columnNames = {CommentVotesConst.S_COMMENT, CommentVotesConst.S_USER}))
public class CommentVotes extends AbstractObject {
    /**
     * Комментарий
     */
    private Comment comment;
    /**
     * Проголосовавший пользователь
     */
    private User user;
    /**
     * Подтверждение комментария (true: +1, false:-1)
     */
    private Boolean confirmation;
    /**
     * Дата голосования
     */
    private Date created;

    {
        setObjectType(EObjectType.COMMENT_VOTES);
    }

    public CommentVotes() {
    }

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = CommentVotesConst.S_COMMENT, nullable = false, updatable = false)
    public Comment getComment() {
        return comment;
    }

    public void setComment(Comment comment) {
        this.comment = comment;
    }

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = CommentVotesConst.S_USER, nullable = false, updatable = false)
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Column(name = CommentVotesConst.S_CONFIRMATION, nullable = false, updatable = false)
    public Boolean getConfirmation() {
        return confirmation;
    }

    public void setConfirmation(Boolean confirmation) {
        this.confirmation = confirmation;
    }

    @Column(name = CommentVotesConst.S_CREATED, nullable = false, unique = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    @Override
    public void prePrePersist() {
        super.prePrePersist();
        this.created=new Date();
    }
}
